import request from '@/utils/request'
import form from '@/utils/form'

const api = 'Notice/'

// post
// @params {sendTime, from, to, url, thumb, content, title type,url}
// @return {*}
export function send({ id, sendTime, from, to, url, thumb, content, title, type, attachments }) {
  return request.put(`${api}info`, {
    data: {
      id, type, sendTime, from, to, url, thumb, content, title, attachments
    }
  }
  )
}

// get => List
// @params { form, to, toCompany, type }
// @return  Array
export function list({ from, to, sendTime, page, type, title }) {
  return request.post(`${api}list`, {
    type: form.toQueryArrays(type),
    to: form.toQueryValue(to),
    title: form.toQueryValue(title),
    from: form.toQueryValue(from),
    sendTime: form.toQueryStartEndByArray(sendTime),
    page
  })
}

// getTagDetails
// params: { id }
export function getDetails(id) {
  return request.get(`${api}Detail`, {
    params: { id }
  })
}

// remove notice
export function remove({ id, sendTime, from, to, url, thumb, content, title, type, attachments }) {
  return request.put(`${api}info`, {
    data: {
      id, sendTime, from, to, url, thumb, content, title, type, attachments,
      isRemoved: true
    }
  })
}

